package com.okilo.online.app.pet

import com.okilo.online.app.configs.OkiloConfigs
import com.okilo.online.app.configs.OkiloConfigs.addParams
import com.okilo.online.app.lib.device.OkiloDevAsyn
import com.okilo.online.app.request.HttpHelper
import com.okilo.online.app.request.IHttpCallback
import com.okilo.online.app.tools.log.OkiloLog
import org.json.JSONObject

/**
 * 数据分析、设备信息上报
 */
object OkiloLibPet {
    /**
     * 获取设备信息上报状态
     */
    fun gOkiloDeviceInfoTypesRequest(){
        val params = JSONObject().addParams().apply {
            put("path",OkiloConfigs.gOkiloRequestPath("DEVICE_TYPES"))
        }
        val httpUrl = OkiloConfigs.gOkiloSubSdkUrl()
        HttpHelper.post(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                when(data.optInt("code")) {
                    0 -> {//成功
                        val obj = data.optJSONObject("obj")
                        obj?.let {
                            val deviceInfoTypes = obj.optString("deviceInfoTypes")
                            OkiloDevAsyn.startAsynTasks(deviceInfoTypes)
                        }
                    }
                    else -> {//失败全部上报

                    }
                }
            }
            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
            }
        })
    }
    /**
     * 提交数据
     */
    fun submitOkiloLibDataRequest(params: JSONObject){
        val requestUrl = OkiloConfigs.gOkiloSubSdkUrl()

        OkiloLog.i("libUrl：  $requestUrl")
        OkiloLog.i("libParams： $params")
        HttpHelper.post(requestUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
            }
        })
    }
}